package com.ysy.serviceImpl;

import com.ysy.dto.DelFileReqDTO;
import com.ysy.factory.FileUploadStrategyFactory;
import com.ysy.persimmons.common.response.Response;
import com.ysy.service.FileService;
import com.ysy.strategy.FileUploadStrategy;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Optional;

@Service
public class FileServiceImpl implements FileService {

    @Resource
    private FileUploadStrategyFactory fileUploadStrategyFactory;


    @Override
    public Response<?> uploadFile(MultipartFile file,Integer type) {
        FileUploadStrategy fileUploadStrategy = fileUploadStrategyFactory.getFileUploadStrategy(type);
        return fileUploadStrategy.upload(file,"","");
    }

    @Override
    public Response<?> delFile(DelFileReqDTO delFileReqDTO) {
        if(delFileReqDTO.getType() == null){
            throw new RuntimeException("参数异常，请求类型不能为空");
        }
        FileUploadStrategy fileUploadStrategy = fileUploadStrategyFactory.getFileUploadStrategy(delFileReqDTO.getType());
        return fileUploadStrategy.delete( delFileReqDTO);
    }
}
